import PubSub from "../utils/PubSub.js";
export default   class Root{



    constructor(){

        this.cache={}; //模块
        this.cacheConfig={} ;
    }

    //获取模块
    findData(moduleName,dir,fsName,loadName ){
        let _this=this;
        let configCache = this.cacheConfig[loadName]
        if(configCache){
            let cacheKey=configCache.findKey(moduleName,dir,fsName,loadName);
            return new Promise(function (resolve, reject) {
                if(!_this.cache[cacheKey]){

                    resolve(_this.cache[cacheKey]);
                }else {
                    let res= _this.load(moduleName,dir,fsName,loadName )

                    res.then(resData =>{
                        _this.cache[cacheKey]=resData;

                        resolve(resData);
                    })
                }
            });
        }else {
            return new Promise(function (resolve, reject) {
                let res= _this.load(moduleName,dir,fsName,loadName)

                res.then(resData =>{

                    resolve(resData);
                })
            });
        }
    }

    configCache(configCache,dir,fsName,loadName){
        this.cacheConfig[loadName]=configCache;
    }
}